import * as types from '../mutations-type'

const namespaced = true;

const state = {
  editor:{
    isEditing: false
  },
  addListShow:false, //右上角加号点击
  tabbarActive: 0, //tabbar 获取的btn
  toast: {
    type: 'html', //loading success fail html
    position: 'middle', //loading top bottom
    message: '疯子阿程超级酷！',
    mask: false,// 是否显示背景蒙层
    forbidClick: false, //是否禁止背景点击
    duration: 2000 //展示时长，如果是0，不消失
  },
  toastMark:0, //toast标记
  notify: {
    message:"消息提示",
    duration: 2000,
    color:'#fff',
    background: '#0f0',
  }, //
  notifyMark: 0, // notify标记

  tabbarlist: [
    {
      icon: 'home-o',
      text: '疯',
      value: '0',
      info: '',
      to: '/home',
      dot: false
    },
    {
      icon: 'search',
      text: '子',
      value: '1',
      info: '',
      to: 'article',
      dot: false
    },
    {
      icon: 'friends-o',
      text: '阿',
      value: '2',
      info: '',
      to: '/write',
      dot: false
    },
    {
      icon: 'setting-o',
      text: '程',
      value: '3',
      info: '2',
      to: 'my',
      dot: true
    }
  ],

}

const mutations = {
  [types.HOME_TABBAR_ACTIVE](state, active) {
    state.tabbarActive = active;
  }

}

const getters = {
  tabbarActive: state => state.tabbarActive,
  tabbarlist: state => state.tabbarlist,
  fzactoast: state => state.toast,
  toastMark: state => state.toastMark,
  fzacnotify: state => state.notify,
  notifyMark: state => state.notifyMark,
}

const actions = {
  showSuccessToast({state}, data) {
    state.toast.type = 'success';
    state.toast.duration = data.duration ? data.duration : state.toast.duration;
    state.toast.forbidClick = data.forbidClick ? data.forbidClick : state.toast.forbidClick; // 禁用背景点击
    state.toast.message = data.message ? data.message : state.toast.message;
    state.toast.position = data.position ? data.position : state.toast.position;
    state.toast.mask = data.mask ? data.mask : state.toast.mask;
    state.toastMark = state.toastMark + 1;
  },
  showFailToast({state}, data) {
    state.toastMark = state.toastMark + 1;
    state.toast.type = 'fail';
    state.toastduration = data.duration ? data.duration : state.toast.duration;
    state.toast.forbidClick = data.forbidClick ? data.forbidClick : state.toast.forbidClick; // 禁用背景点击
    state.toast.message = data.message ? data.message : state.toast.message;
    state.toast.position = data.position ? data.position : state.toast.position;
    state.toast.mask = data.mask ? data.mask : state.toast.mask
    state.toastMark = state.toastMark + 1;
  },
  showLoadingToast({state}, data) {
    state.toastMark = state.toastMark + 1;
    state.toast.type = 'loading';
    state.toastduration = data.duration ? data.duration : state.toast.duration;
    state.toast.forbidClick = data.forbidClick ? data.forbidClick : state.toast.forbidClick; // 禁用背景点击
    state.toast.message = data.message ? data.message : state.toast.message;
    state.toast.position = data.position ? data.position : state.toast.position;
    state.toast.mask = data.mask ? data.mask : state.toast.mask
    state.toastMark = state.toastMark + 1;
  },
  showTextToast({state}, data) {
    state.toastMark = state.toastMark + 1;
    state.toastduration = data.duration ? data.duration : state.toast.duration;
    state.toast.forbidClick = data.forbidClick ? data.forbidClick : state.toast.forbidClick; // 禁用背景点击
    state.toast.message = data.message ? data.message : state.toast.message;
    state.toast.position = data.position ? data.position : state.toast.position;
    state.toast.mask = data.mask ? data.mask : state.toast.mask
    state.toastMark = state.toastMark + 1;
  },

  showSuccessNotify({state}, message) {
    state.notify.message = message;
    state.notify.color= '#fff';
    state.notify.background= '#7ab893';
    state.notifyMark = state.notifyMark + 1;
  },
  showErrorNotify({state}, message) {
    state.notify.message = message;
    state.notify.color= '#fff';
    state.notify.background= '#ff4444';
    state.notifyMark = state.notifyMark + 1;
  },
  showWarnNotify({state}, message) {
    state.notify.message = message;
    state.notify.color= '#fff';
    state.notify.background= '#ffcc00';
    state.notifyMark = state.notifyMark + 1;
  },
}

export default {
  namespaced,
  state,
  mutations,
  actions,
  getters
}
